home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Atlanta_1990 / Atlanta-Devcon.2 / Libraries / DOS / exall.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  2.1 KB  |  105 lines

  1. /*
  2.  * Copyright (C) 1990 Commodore-Amiga, Inc.
  3.  * All rights reserved
  4.  */
  5.  
  6.  
  7. /* An example of how to use ExAll.
  8.  * Compiled with Lattice C 5.05: lc -cfist -v -L exall.c
  9.  *
  10.  * Warning: the prototype for ExAll() should be:
  11.  *
  12.  * LONG ExAll( BPTR, struct ExAllData *, long, long, 
  13.  *             struct ExAllControl * );
  14.  */
  15.  
  16. #include <exec/types.h>
  17. #include <exec/ports.h>
  18. #include <exec/memory.h>
  19. #include <dos/dos.h>
  20. #include <dos/dosextens.h>
  21. #include <dos/exall.h>
  22. #include <clib/dos_protos.h>
  23. #include <clib/exec_protos.h>
  24.  
  25. /* normally you'ld include pragmas here */
  26.  
  27. #define BUFFSIZE 2048
  28.  
  29. int main(int, char **);
  30.  
  31. int
  32. main(argc,argv)
  33.     int argc;
  34.     char *argv[];
  35. {
  36.     BPTR obj_lock;
  37.     LONG res2,more = TRUE;
  38.     struct ExAllData *Buffer = NULL,*ead;
  39.     struct ExAllControl *control = NULL;
  40.     LONG rc = RETURN_ERROR;
  41.  
  42.   /* ugly argument parsing */
  43.   if( argc == 2 ) {
  44.  
  45.     /* control MUST be allocated by AllocDosObject! */
  46.     control=(struct ExAllControl *) AllocDosObject(DOS_EXALLCONTROL,NULL);
  47.     Buffer=(struct ExAllData *) AllocMem(BUFFSIZE,MEMF_PUBLIC|MEMF_CLEAR);
  48.  
  49.     /* always check allocations! */
  50.     if (!control || !Buffer)
  51.         goto cleanup;
  52.  
  53.     /* lock the directory */
  54.     if (obj_lock = Lock(argv[1],SHARED_LOCK)) {
  55.  
  56.       control->eac_LastKey = 0;    /* paranoia */
  57.  
  58.       do { /* while more */
  59.  
  60.         more = ExAll(obj_lock,Buffer,BUFFSIZE,ED_TYPE,control);
  61.         res2 = IoErr();
  62.         if (!more && res2 != ERROR_NO_MORE_ENTRIES)
  63.         {
  64.         VPrintf("Abnormal exit, error = %ld\n",&res2);
  65.         break;
  66.         }
  67.  
  68.         /* remember, VPrintf wants a pointer to arguments! */
  69.         VPrintf("Returned %ld entries:\n\n",&(control->eac_Entries));
  70.  
  71.         if (control->eac_Entries)
  72.         {
  73.         ead = Buffer;
  74.         do {
  75.             VPrintf("%s",(LONG *) &(ead->ed_Name));
  76.             if (ead->ed_Type > 0)
  77.                 PutStr(" (dir)\n");
  78.             else
  79.                 PutStr(" (file)\n");
  80.  
  81.             ead = ead->ed_Next;
  82.         } while (ead);
  83.         }
  84.  
  85.         rc = RETURN_OK;    /* success */
  86.  
  87.       } while (more);
  88.  
  89.       UnLock(obj_lock);
  90.  
  91.     } else VPrintf("Couldn't find %s\n",(LONG *) &(argv[1]));
  92.  
  93. cleanup:
  94.     if (Buffer)  FreeMem(Buffer,BUFFSIZE);
  95.     if (control) FreeDosObject(DOS_EXALLCONTROL,control);
  96.  
  97.     return(rc);
  98.  
  99.     } else {
  100.       VPrintf("Usage: %s dirname\n",(LONG *) &(argv[0]));
  101.       return(rc);
  102.     }
  103. }
  104.  
  105.